package com.wanqing.mapper;

import com.github.pagehelper.Page;
import com.wanqing.dto.GoodsSalesDTO;
import com.wanqing.dto.OrdersPageQueryDTO;
import com.wanqing.entity.Orders;
import com.wanqing.vo.OrderVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
    /**
     * 插入订单数据
     *
     * @param orders
     */
    void insert(Orders orders);

    /**
     * 根据订单号查询订单
     *
     * @param orderNumber
     */
    @Select("select * from orders where number = #{orderNumber}")
    Orders getByNumber(String orderNumber);

    /**
     * 修改订单信息
     *
     * @param orders
     */
    void update(Orders orders);

    Page<OrderVO> pageQuery(OrdersPageQueryDTO ordersPageQueryDTO);

    OrderVO details(Long id);

    Page<Orders> pageQuerys(OrdersPageQueryDTO ordersPageQueryDTO);

    /**
     * 根据状态统计订单数量
     *
     * @param status
     */
    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer status);

    /**
     * 根据状态和下单时间查询订单
     *
     * @param status
     * @param orderTime
     * @return
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndTimeLT(Integer status, LocalDateTime orderTime);

    Long countUser(@Param("begin") LocalDateTime beginTime, @Param("end") LocalDateTime endTime);

    Integer getOrderCount(@Param("begin") LocalDateTime beginTime, @Param("end") LocalDateTime endTime, @Param("status") Integer status);

    List<GoodsSalesDTO> getSalesTop10(@Param("begin") LocalDateTime beginTime, @Param("end") LocalDateTime endTime);

    Double sumTurnover(@Param("begin") LocalDateTime beginTime, @Param("end") LocalDateTime endTime, @Param("status") Integer status);

    List<GoodsSalesDTO> getSalesPenultimate5(@Param("begin") LocalDateTime beginTime, @Param("end") LocalDateTime endTime);
}
